home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Development / Source / MultiSession 1.04 Source / Core 27⁄June⁄1993 / CVScrollBar.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-06  |  10.2 KB  |  426 lines  |  [TEXT/KAHL]

  1. /* CVScrollBar.c */
  2.  
  3. #include "CVScrollBar.h"
  4. #include "CWindow.h"
  5.  
  6.  
  7. #define UpArrowID (128)
  8. #define UpArrowSelectedID (132)
  9. #define DownArrowID (129)
  10. #define DownArrowSelectedID (133)
  11.  
  12.  
  13. void            CVScrollBar::IVScrollBar(LongPoint Start, LongPoint Extent,
  14.                                 CViewRect* TheOwner, CWindow* TheWindow, CEnclosure* TheEnclosure)
  15.     {
  16.         Extent.x = 16;
  17.         Owner = TheOwner;
  18.         IViewRect(Start,Extent,TheWindow,TheEnclosure);
  19.         NumCells = 1;
  20.         CellIndex = 0;
  21.         RecalcScrollRects();
  22.         CurrentOperation = mNone;
  23.     }
  24.  
  25.  
  26. void            CVScrollBar::DoMouseDown(MyEventRec Event)
  27.     {
  28.         long                Length;
  29.         LongPoint        MouseLoc;
  30.         MyBoolean        OutOfRange;
  31.         short                XorPosition;
  32.         MyBoolean        ImageXored;
  33.  
  34.         CurrentOperation = FindPart(MyGlobalToLocal(Event.Where));
  35.         switch (CurrentOperation)
  36.             {
  37.                 case mUpOne:
  38.                     if (VScrollable && Enabled)
  39.                         {
  40.                             do{
  41.                                     RedrawVBar();
  42.                                     if (CurrentOperation == mUpOne)
  43.                                         {
  44.                                             Owner->Hook(VScrollUpOne,0,0);
  45.                                         }
  46.                                     CurrentOperation = FindPart(MyGlobalToLocal(GetLongMouseLoc()));
  47.                                     if (CurrentOperation != mUpOne)
  48.                                         {
  49.                                             CurrentOperation = mNone;
  50.                                         }
  51.                                     RelinquishCPU();
  52.                                     SendIdleToAll();
  53.                                 } while (WaitMouseUp());
  54.                             CurrentOperation = mNone;
  55.                             RedrawVBar();
  56.                         }
  57.                     break;
  58.                 case mUpPage:
  59.                     if (VScrollable && Enabled)
  60.                         {
  61.                             do{
  62.                                     RedrawVBar();
  63.                                     if (CurrentOperation == mUpPage)
  64.                                         {
  65.                                             Owner->Hook(VScrollUpPage,0,0);
  66.                                         }
  67.                                     CurrentOperation = FindPart(MyGlobalToLocal(GetLongMouseLoc()));
  68.                                     if (CurrentOperation != mUpPage)
  69.                                         {
  70.                                             CurrentOperation = mNone;
  71.                                         }
  72.                                     RelinquishCPU();
  73.                                     SendIdleToAll();
  74.                                 } while (WaitMouseUp());
  75.                             CurrentOperation = mNone;
  76.                             RedrawVBar();
  77.                         }
  78.                     break;
  79.                 case mDownOne:
  80.                     if (VScrollable && Enabled)
  81.                         {
  82.                             do{
  83.                                     RedrawVBar();
  84.                                     if (CurrentOperation == mDownOne)
  85.                                         {
  86.                                             Owner->Hook(VScrollDownOne,0,0);
  87.                                         }
  88.                                     CurrentOperation = FindPart(MyGlobalToLocal(GetLongMouseLoc()));
  89.                                     if (CurrentOperation != mDownOne)
  90.                                         {
  91.                                             CurrentOperation = mNone;
  92.                                         }
  93.                                     RelinquishCPU();
  94.                                     SendIdleToAll();
  95.                                 } while (WaitMouseUp());
  96.                             CurrentOperation = mNone;
  97.                             RedrawVBar();
  98.                         }
  99.                     break;
  100.                 case mDownPage:
  101.                     if (VScrollable && Enabled)
  102.                         {
  103.                             do{
  104.                                     RedrawVBar();
  105.                                     if (CurrentOperation == mDownPage)
  106.                                         {
  107.                                             Owner->Hook(VScrollDownPage,0,0);
  108.                                         }
  109.                                     CurrentOperation = FindPart(MyGlobalToLocal(GetLongMouseLoc()));
  110.                                     if (CurrentOperation != mDownPage)
  111.                                         {
  112.                                             CurrentOperation = mNone;
  113.                                         }
  114.                                     RelinquishCPU();
  115.                                     SendIdleToAll();
  116.                                 } while (WaitMouseUp());
  117.                             CurrentOperation = mNone;
  118.                             RedrawVBar();
  119.                         }
  120.                     break;
  121.                 case mVBox:
  122.                     if (VScrollable && Enabled)
  123.                         {
  124.                             if ((Event.Modifiers & optionKey) != 0)
  125.                                 {
  126.                                     short        OldMouseLoc = -32767;
  127.  
  128.                                     ImageXored = False;
  129.                                     /* setting up drawing environment */
  130.                                     SetUpPort();
  131.                                     Length = PageDownZoneExt.y + PageUpZoneExt.y;
  132.                                     do{
  133.                                             static LongPoint    VXorBoxExt = {14,16};
  134.  
  135.                                             /* removing any image already there */
  136.                                             do
  137.                                                 {
  138.                                                     MouseLoc = MyGlobalToLocal(GetLongMouseLoc());
  139.                                                     RelinquishCPU();
  140.                                                     SendIdleToAll();
  141.                                                 } while ((MouseLoc.y - 16 - 8 == OldMouseLoc) && WaitMouseUp());
  142.                                             SetUpPort();
  143.                                             Window->ResetPen();
  144.                                             Window->SetPenMode(srcXor);
  145.                                             Window->SetPattern(dkGray);
  146.                                             if (ImageXored)
  147.                                                 {
  148.                                                     Window->LFrameRect(LongPointOf(Extent.x - 16 + 1,
  149.                                                         XorPosition + 16),VXorBoxExt);
  150.                                                     ImageXored = False;
  151.                                                 }
  152.                                             /* finding new image position */
  153.                                             OutOfRange = False;
  154.                                             OldMouseLoc = MouseLoc.y - 16 - 8;
  155.                                             XorPosition = OldMouseLoc;
  156.                                             if ((MouseLoc.x < (Extent.x - 16 - 24))
  157.                                                 || (MouseLoc.x > (Extent.x + 24)))
  158.                                                 {
  159.                                                     OutOfRange = True;
  160.                                                 }
  161.                                             if (XorPosition < 0)
  162.                                                 {
  163.                                                     XorPosition = 0;
  164.                                                 }
  165.                                             if (XorPosition > Length)
  166.                                                 {
  167.                                                     XorPosition = Length;
  168.                                                 }
  169.                                             /* putting new image position */
  170.                                             if (!OutOfRange)
  171.                                                 {
  172.                                                     Window->LFrameRect(LongPointOf(Extent.x - 16 + 1,
  173.                                                         XorPosition + 16),VXorBoxExt);
  174.                                                     ImageXored = True;
  175.                                                 }
  176.                                             RelinquishCPU();
  177.                                             SendIdleToAll();
  178.                                             SetUpPort();
  179.                                         } while (WaitMouseUp());
  180.                                     if (ImageXored)
  181.                                         {
  182.                                             Owner->Hook(VScrollToLocation,
  183.                                                 ((NumCells - 1) * XorPosition) / Length,NumCells);
  184.                                         }
  185.                                 }
  186.                              else
  187.                                 {
  188.                                     do{
  189.                                             Length = PageUpZoneExt.y + PageDownZoneExt.y;
  190.                                             MouseLoc = MyGlobalToLocal(GetLongMouseLoc());
  191.                                             MouseLoc.y = MouseLoc.y - 16 - 8;
  192.                                             if (MouseLoc.y < 0)
  193.                                                 {
  194.                                                     MouseLoc.y = 0;
  195.                                                 }
  196.                                             if (MouseLoc.y > Length)
  197.                                                 {
  198.                                                     MouseLoc.y = Length;
  199.                                                 }
  200.                                             Owner->Hook(VScrollToLocation,((NumCells - 1) * MouseLoc.y
  201.                                                 + (Length / 2)) / Length,NumCells);
  202.                                             RelinquishCPU();
  203.                                             SendIdleToAll();
  204.                                         } while (WaitMouseUp());
  205.                                 }
  206.                         }
  207.                     break;
  208.             }
  209.         CurrentOperation = mNone;
  210.     }
  211.  
  212.  
  213. short            CVScrollBar::FindPart(LongPoint Where)
  214.     {
  215.         if (LongPtInRect(Where,OneUpZoneTL,OneUpZoneExt))
  216.             {
  217.                 return mUpOne;
  218.             }
  219.         if (LongPtInRect(Where,PageUpZoneTL,PageUpZoneExt))
  220.             {
  221.                 return mUpPage;
  222.             }
  223.         if (LongPtInRect(Where,VScrollZoneTL,VScrollZoneExt))
  224.             {
  225.                 return mVBox;
  226.             }
  227.         if (LongPtInRect(Where,PageDownZoneTL,PageDownZoneExt))
  228.             {
  229.                 return mDownPage;
  230.             }
  231.         if (LongPtInRect(Where,OneDownZoneTL,OneDownZoneExt))
  232.             {
  233.                 return mDownOne;
  234.             }
  235.         return mNone;
  236.     }
  237.  
  238.  
  239. void            CVScrollBar::RedrawVBar(void)
  240.     {
  241.         SetUpPort();
  242.         Window->ResetPen();
  243.         if (Suspended || !Enabled)
  244.             {
  245.                 Window->LEraseRect(LongPointOf(1,1),LongPointOf(Extent.x - 2,Extent.y - 2));
  246.                 Window->LFrameRect(ZeroPoint,Extent);
  247.             }
  248.          else
  249.             {
  250.                 if (CurrentOperation == mUpOne)
  251.                     {
  252.                         Window->LDrawPicture(GetPic(UpArrowSelectedID),
  253.                             OneUpZoneTL,OneUpZoneExt);
  254.                     }
  255.                  else
  256.                     {
  257.                         Window->LDrawPicture(GetPic(UpArrowID),
  258.                             OneUpZoneTL,OneUpZoneExt);
  259.                     }
  260.                 if (CurrentOperation == mDownOne)
  261.                     {
  262.                         Window->LDrawPicture(GetPic(DownArrowSelectedID),
  263.                             OneDownZoneTL,OneDownZoneExt);
  264.                     }
  265.                  else
  266.                     {
  267.                         Window->LDrawPicture(GetPic(DownArrowID),
  268.                             OneDownZoneTL,OneDownZoneExt);
  269.                     }
  270.                 if (VScrollable)
  271.                     {
  272.                         Window->SetPattern(ltGray);
  273.                         Window->LPaintRect(LongPointOf(PageUpZoneTL.x + 1,PageUpZoneTL.y),
  274.                             LongPointOf(PageUpZoneExt.x - 2,PageUpZoneExt.y));
  275.                         Window->LPaintRect(LongPointOf(PageDownZoneTL.x + 1,PageDownZoneTL.y),
  276.                             LongPointOf(PageDownZoneExt.x - 2,PageDownZoneExt.y));
  277.                         Window->SetPattern(black);
  278.                         Window->DrawLine(PageUpZoneTL,LongPointOf(0,PageUpZoneExt.y
  279.                             + VScrollZoneExt.y + PageDownZoneExt.y));
  280.                         Window->DrawLine(LongPointOf(PageUpZoneTL.x + 15,PageUpZoneTL.y),
  281.                             LongPointOf(0,PageUpZoneExt.y + VScrollZoneExt.y + PageDownZoneExt.y));
  282.                         Window->LEraseRect(LongPointOf(VScrollZoneTL.x + 1,VScrollZoneTL.y + 1),
  283.                             LongPointOf(VScrollZoneExt.x - 2,VScrollZoneExt.y - 2));
  284.                         Window->LFrameRect(VScrollZoneTL,VScrollZoneExt);
  285.                     }
  286.                  else
  287.                     {
  288.                         Window->LEraseRect(LongPointOf(VScrollZoneTL.x + 1,VScrollZoneTL.y),
  289.                             LongPointOf(VScrollZoneExt.x - 2,VScrollZoneExt.y));
  290.                         Window->DrawLine(VScrollZoneTL,LongPointOf(0,VScrollZoneExt.y));
  291.                         Window->DrawLine(LongPointOf(VScrollZoneTL.x + 15,VScrollZoneTL.y),
  292.                             LongPointOf(0,VScrollZoneExt.y));
  293.                     }
  294.             }
  295.     }
  296.  
  297.  
  298. void            CVScrollBar::DoUpdate(void)
  299.     {
  300.         RedrawVBar();
  301.     }
  302.  
  303.  
  304. void            CVScrollBar::DoResume(void)
  305.     {
  306.         inherited::DoResume();
  307.         RedrawVBar();
  308.     }
  309.  
  310.  
  311. void            CVScrollBar::DoSuspend(void)
  312.     {
  313.         inherited::DoSuspend();
  314.         RedrawVBar();
  315.     }
  316.  
  317.  
  318. void            CVScrollBar::DoEnable(void)
  319.     {
  320.         inherited::DoEnable();
  321.         RedrawVBar();
  322.     }
  323.  
  324.  
  325. void            CVScrollBar::DoDisable(void)
  326.     {
  327.         inherited::DoDisable();
  328.         RedrawVBar();
  329.     }
  330.  
  331.  
  332.  
  333. void                CVScrollBar::RecalcScrollRects(void)
  334.     {
  335.         long        Length;
  336.         long        BoxPos;
  337.  
  338.         Length = Extent.y;
  339.         OneUpZoneTL.x = Extent.x - 16;
  340.         OneUpZoneTL.y = 0;
  341.         OneUpZoneExt.x = 16;
  342.         OneUpZoneExt.y = 16;
  343.         OneDownZoneTL.x = Extent.x - 16;
  344.         OneDownZoneTL.y = Length - 16;
  345.         OneDownZoneExt.x = 16;
  346.         OneDownZoneExt.y = 16;
  347.         if (NumCells <= 1)
  348.             {
  349.                 if (CellIndex == 0)
  350.                     {
  351.                         VScrollable = False;
  352.                         VScrollZoneTL.x = Extent.x - 16;
  353.                         VScrollZoneTL.y = 16;
  354.                         VScrollZoneExt.x = 16;
  355.                         VScrollZoneExt.y = Length - 16 - 16;
  356.                     }
  357.                  else
  358.                     {
  359.                         NumCells = -NumCells;
  360.                         goto TryAgainPoint;
  361.                     }
  362.             }
  363.          else
  364.             {
  365.              TryAgainPoint:
  366.                 VScrollable = True;
  367.                 if (NumCells == 1)
  368.                     {
  369.                         if (CellIndex < 0)
  370.                             {
  371.                                 BoxPos = 0;
  372.                             }
  373.                          else
  374.                             {
  375.                                 BoxPos = Length - 3*16;
  376.                             }
  377.                     }
  378.                  else
  379.                     {
  380.                         BoxPos = ((Length - 3*16)
  381.                             * ((long double)CellIndex) / ((long double)(NumCells - 1)));
  382.                         if (BoxPos < 0)
  383.                             {
  384.                                 BoxPos = 0;
  385.                             }
  386.                         if (BoxPos > Length - 3*16)
  387.                             {
  388.                                 BoxPos = Length - 3*16;
  389.                             }
  390.                     }
  391.                 PageUpZoneTL.x = Extent.x - 16;
  392.                 PageUpZoneTL.y = 16;
  393.                 PageUpZoneExt.x = 16;
  394.                 PageUpZoneExt.y = BoxPos;
  395.                 VScrollZoneTL.x = Extent.x - 16 + 1;
  396.                 VScrollZoneTL.y = BoxPos + 16;
  397.                 VScrollZoneExt.x = 14;
  398.                 VScrollZoneExt.y = 16;
  399.                 PageDownZoneTL.x = Extent.x - 16;
  400.                 PageDownZoneTL.y = BoxPos + 16 + 16;
  401.                 PageDownZoneExt.x = 16;
  402.                 PageDownZoneExt.y = (Length - 3*16) - BoxPos;
  403.             }
  404.     }
  405.  
  406.  
  407. void            CVScrollBar::SetPosition(long NewCellIndex, long NewNumCells)
  408.     {
  409.         CellIndex = NewCellIndex;
  410.         NumCells = NewNumCells;
  411.         RecalcScrollRects();
  412.         if ((!Suspended) && Enabled)
  413.             {
  414.                 RedrawVBar();
  415.             }
  416.     }
  417.  
  418.  
  419. void            CVScrollBar::RecalcLocations(LongPoint EnclosureVisRectStart,
  420.                         LongPoint EnclosureVisRectExtent, LongPoint EnclosureOrigin)
  421.     {
  422.         inherited::RecalcLocations(EnclosureVisRectStart,EnclosureVisRectExtent,
  423.             EnclosureOrigin);
  424.         RecalcScrollRects();
  425.     }
  426.